#ifndef FFMPEGEXTRA_EYERWASMEVENTLOOP_HPP
#define FFMPEGEXTRA_EYERWASMEVENTLOOP_HPP

#include <thread>
#include <mutex>
#include <queue>

#include "EyerWASMEvent.hpp"

namespace Eyer
{
    class EyerWASMEventLoop
    {
    public:
        static EyerWASMEventLoop * GetInstance();
        static EyerWASMEventLoop * GetMainThreadInstance();
    private:
        static EyerWASMEventLoop * instance;
        static std::mutex instanceMut;

        static EyerWASMEventLoop * mainThreadInstance;
        static std::mutex mainThreadInstanceMut;

    private:
        EyerWASMEventLoop(bool isNewThread);
    public:
        int Run();
        int EventLoop();

        int PutEvent(const std::shared_ptr<EyerWASMEvent> & event);
    private:
        std::thread * t = nullptr;

        std::mutex eventQueueMut;
        std::queue<std::shared_ptr<EyerWASMEvent>> eventQueue;
    };
}

#endif //FFMPEGEXTRA_EYERWASMEVENTLOOP_HPP
